package ai.people.core.web.exception.handler;

import ai.people.netmon.framework.exception.enums.CommonEnum;
import ai.people.netmon.framework.model.response.Result;
import ai.people.netmon.framework.utils.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 兜底的异常
 *
 * @author yuanqinglong
 * @date 2022/4/15 18:17
 */
@Order
@RestControllerAdvice
public class RevealExceptionHandler {

    Logger logger = LoggerFactory.getLogger(RevealExceptionHandler.class);

    /**
     * 异常处理程序
     *
     * @param throwable 异常
     * @return {@link Result}<{@link T}>
     */
    @ExceptionHandler(Throwable.class)
    public <T> Result<T> throwable(Throwable throwable) {
        logger.error("系统异常", throwable);
        return ResultUtil.error(CommonEnum.SERVER_ERROR);
    }
}
